/*
 /	This file is part of Answerkeys Disabler
 /
 /	Answerkeys Disabler is free software: you can redistribute it and/or modify
 /	it under the terms of the GNU General Public License as published by
 /	the Free Software Foundation, either version 3 of the License, or
 /	(at your option) any later version.
 /
 /	Answerkeys Disabler is distributed in the hope that it will be useful,
 /	but WITHOUT ANY WARRANTY; without even the implied warranty of
 /	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 /	GNU General Public License for more details.
 /
 /	You should have received a copy of the GNU General Public License
 /	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 /
 /	Copyright 2008 Daan van Dijk (drvdijk@gmail.com)
 */

#include "stdafx.h"
#include "touchpanel.h"

CTouchPanel::CTouchPanel()
{
	m_CoreDLL = LoadLibrary(L"coredll.dll");
	m_fpSetKMode = (SetKMode_t)GetProcAddress(m_CoreDLL, L"SetKMode");

	m_TouchDLL = LoadLibrary(L"touch.dll");
	if(m_TouchDLL != NULL)
	{
		m_fpTouchPanelPowerHandler = (TouchPanelPowerHandler_t)GetProcAddress(m_TouchDLL, L"TouchPanelPowerHandler");
		return;
	}

	m_fpTouchPanelPowerHandler = NULL;
}


CTouchPanel::~CTouchPanel()
{
	if(m_TouchDLL !=NULL)
	{
		FreeLibrary(m_TouchDLL);
	}

	if(m_CoreDLL != NULL)
	{
		FreeLibrary(m_CoreDLL);
	}
}

void CTouchPanel::SetDisabled(bool bEnable)
{
	BOOL bOldMode = m_fpSetKMode(TRUE);
	m_fpTouchPanelPowerHandler(bEnable ? TRUE : FALSE);
	m_fpSetKMode(bOldMode);
}

bool CTouchPanel::isLoaded()
{
	return m_fpTouchPanelPowerHandler != NULL;
}
